package com.firefighting.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.firefighting.entity.Building;
import com.firefighting.entity.Contract;
import com.firefighting.entity.Enclosure;
import com.firefighting.entity.Task;
import com.firefighting.entity.User;
import com.firefighting.entity.UserBasicInfo;
import com.firefighting.service.BuildingService;
import com.firefighting.service.ContractService;
import com.firefighting.service.EnclosureService;
import com.firefighting.service.LocationService;
import com.firefighting.service.TaskService;
import com.firefighting.service.UserBasicInfoService;
import com.firefighting.util.WriterUtil;

@Controller
@RequestMapping("index")
public class IndexController {

	
	@Autowired
	private LocationService locationService;
	@Autowired
	private UserBasicInfoService userbasic;
	@Autowired
	private ContractService contractservice;
	
	/**
	 * @function 展示企业合同信息列表
	 * @author Hanjd
	 * 
	 * @return
	 * 
	 * 
	 */
	@RequestMapping("getAllcontract")
	private String getBuildingInfo(HttpServletRequest request, Model model)throws JsonGenerationException, JsonMappingException, IOException
	{
		List<UserBasicInfo> nameList = new ArrayList<UserBasicInfo>(); 
		List<Contract> projectList = new ArrayList<Contract>();
		User user = (User) request.getSession().getAttribute("currentUser");
		int roleId = user.getRoleid();
		String username = user.getUsername();
		int enterpriseId = -1;
		if(roleId!=9){
			enterpriseId = userbasic.queryEnterpriseIdByUsername(username);
		}
		
		List<HashMap<String, Object>> contractList = new ArrayList<HashMap<String,Object>>();
		ObjectMapper objectMapper = new ObjectMapper();
		
		if(roleId == 9){
			contractList = contractservice.queryIndexContractHash(enterpriseId);
			model.addAttribute("locatonList", objectMapper.writeValueAsString(contractList));
			return "indexForFire";
		}else if(roleId == 2){
			contractList = contractservice.queryIndexContractByLeader(username);
			model.addAttribute("locatonList", objectMapper.writeValueAsString(contractList));
			return "index";
		}else if(roleId == 1){
			contractList = contractservice.queryIndexContractHash(enterpriseId);
			model.addAttribute("locatonList", objectMapper.writeValueAsString(contractList));
			return "index";
		}else{
			contractList = contractservice.queryIndexContractHash(enterpriseId);
			model.addAttribute("locatonList", objectMapper.writeValueAsString(contractList));
			return "index";
		}
		
	
	}
	
}
